package org.platform.processor.monitor.job;

import lombok.extern.slf4j.Slf4j;
import org.platform.core.JobManager;
import org.platform.processor.monitor.data.CacheLibraryPO;
import org.quartz.*;
import org.quartz.impl.JobDetailImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用于查看缓存数据工具类
 *
 * @author FengJie
 * @date 2018/6/23
 */
@Service
@Slf4j
public class PrintJob implements InterruptableJob {
    private static final String JOB_KEY = "PromoteTaskJob";
    @Autowired
    private JobManager job;

    @Override
    public void interrupt() {
    }

    @Override
    public void execute(JobExecutionContext context) {
        try {
            CacheLibraryPO data = CacheLibraryPO.getCacheLibraryPO();
            log.info("标准参照源大小:{}", data.getStandardReferenceSourceMap().size());
            log.info("设备队列的大小:{}", data.getDeviceQueue().size());
            log.info("设备属性队列的大小:{}", data.getDevicePropertyQueue().size());
            log.info("异常设备队列大小:{}", data.getAbnormalDeviceMap().size());
            log.info("报警设备的大小:{}", data.getAlarmDeviceMap().size());
        } catch (Exception e) {
            log.error("定时线程【{}】发生错误,异常信息", JOB_KEY, e);
        }
    }


    //@PostConstruct
    public void init() {
        JobDetailImpl jd = new JobDetailImpl();
        jd.setJobClass(PrintJob.class);
        jd.setKey(JobKey.jobKey(JOB_KEY));

        SimpleTrigger trigger = TriggerBuilder.newTrigger()
                .withSchedule(SimpleScheduleBuilder
                        .simpleSchedule()
                        .withIntervalInSeconds(60)
                        .repeatForever())
                .startNow()
                .build();

        job.register(jd, trigger);
    }

}
